package com.artron.mediaartron.ui.fragment.custom;

import android.support.annotation.DrawableRes;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.artron.baselib.base.BaseStaticFragment;
import com.artron.baselib.utils.ToastUtil;
import com.artron.baselib.utils.UIUtils;
import com.artron.mediaartron.R;
import com.artron.mediaartron.ui.activity.HomeDetailActivity;

import butterknife.BindView;

/**
 * Class description here
 *
 * @author doing
 * @version 1.0.0
 * @since 2017-09-20.
 */

public class CustomMadeItemFragment extends BaseStaticFragment implements View.OnClickListener {

    @BindView(R.id.CustomMadeItemFragment_iv_bg)
    protected ImageView mIvBg;
    @BindView(R.id.CustomMadeItemFragment_tv_title)
    protected TextView mTvTitle;
    @BindView(R.id.CustomMadeItemFragment_tv_sub_title)
    protected TextView mTvSubTitle;
    @BindView(R.id.CustomMadeItemFragment_btn_made)
    protected Button mBtnMade;
    private int mPosition;

    public static CustomMadeItemFragment newInstance(int position) {
        CustomMadeItemFragment fragment = new CustomMadeItemFragment();
        fragment.init(position);
        return fragment;
    }

    private void init(int position) {
        mPosition = position;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_custom_made_item;
    }

    @Override
    protected void initView() {
        mIvBg.setImageResource(getResourceId(mPosition));
        mTvTitle.setText(getTitle(mPosition));
        mTvSubTitle.setText(getSubTitle(mPosition));

        mBtnMade.setOnClickListener(this);
    }

    @DrawableRes
    private int getResourceId(int position) {
        switch (position) {
            case 0:
                return R.drawable.ic_calendary;
            case 1:
                return R.drawable.ic_voyage;
            case 2:
                return R.drawable.ic_art_desk_calendar;
            case 3:
                return R.drawable.ic_frame_blocking;
            case 4:
                return R.drawable.ic_poster;
        }
        return 0;
    }

    @HomeDetailActivity.Type
    private int getFragmentType(int position) {
        switch (position) {
            case 0:
                return HomeDetailActivity.CALENDAR;
            case 1:
                return HomeDetailActivity.VOYAGE;
            case 2:
                return HomeDetailActivity.ART_DESK_CALENDAR;
            case 3:
                return HomeDetailActivity.CUSTOM_MADE;
            case 4:
                return HomeDetailActivity.POSTER;
        }
        return HomeDetailActivity.VOYAGE;
    }

    private String getTitle(int position) {
        if (position == 1) {
            return "";
        }
        return UIUtils.getStringArray(R.array.CustomMadeTitle)[position];
    }

    private String getSubTitle(int position) {
        return UIUtils.getStringArray(R.array.CustomMadeSubTitle)[position];
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.CustomMadeItemFragment_btn_made:
                HomeDetailActivity.start(mContext, getFragmentType(mPosition));
                break;
        }
    }
}
